import { ChangeDetectionStrategy, Component } from '@angular/core';
import {Menu, MenuService} from "@delon/theme";
import {PlatformLocation} from "@angular/common";
import {filter, map, of, scan} from "rxjs";

@Component({
  selector: 'app-dashboard',
  templateUrl: './dashboard.component.html',
  styles: [`
  .div{
    display:flex;
    justify-content: space-between;
    flex-wrap: wrap;
  }
  .item{
    flex:1;
    margin: 12px;
    padding:8px;
    font-size:20px;
    text-align:center;
    min-width:200px;
  }
  .item:nth-of-type(odd){
    background: #0e4980;
    color:#fff;
  }
  .item:nth-of-type(even){
    background: #5cb85c;
  }
  .item a{
    color:#fff;
  }
  `],
  changeDetection: ChangeDetectionStrategy.OnPush
})
export class DashboardComponent {
  constructor(
    private platformLocation: PlatformLocation,
    private menuService: MenuService
  ){
    this.menuDemo();
    this.pipeDemo();
  }

  menuDemo(){
    const url = this.platformLocation.hash.substr(1);
    const menu = this.menuService.find({url}) as Menu;
    this.menuService.setItem('text',menu);
  }

  pipeDemo(){
    let source = of([1, 2, 3, 45, 56, 7, 7])
      .pipe(
        map(item=> {console.log('map: ', item); return item;})
      );
    source.subscribe(v=>console.log('pipeDemo: ', v));
  }
}
